//请实现一个函数，把字符串 s 中的每个空格替换成"%20"。 
//
// 
//
// 示例 1： 
//
// 输入：s = "We are happy."
//输出："We%20are%20happy." 
//
// 
//
// 限制： 
//
// 0 <= s 的长度 <= 10000 
// 👍 56 👎 0
#include <iostream>
using namespace std;

//leetcode submit region begin(Prohibit modification and deletion)
class Solution {
public:
    string replaceSpace(string s) {
        int count = 0,len = s.size();
        for (char c : s){
            if (c == ' ')
                count++;
        }
        s.resize(len+2*count);
        for (int i = len-1, j = s.size()-1; i  < j ; i--,j--) {
            if (s[i] != ' '){
                s[j] = s[i];
            } else{
                s[j - 2] = '%';
                s[j - 1] = '2';
                s[j] = '0';
                j -= 2;
            }
            return s;
        }
    }
};
//leetcode submit region end(Prohibit modification and deletion)
